#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @author: zzll0909
# @file: 34.py
# @time: 2025/1/22
# @software: PyCharm
from typing import List

class Solution:
    def searchRange(self, nums: List[int], target: int) -> List[int]:
        lp = 0
        rp = len(nums) - 1
        result = [-1, -1]
        while lp <= rp:
            mp = (lp + rp) // 2
            if nums[mp] == target:
                lp = mp
                rp = mp
                while lp > 0 and nums[lp - 1] == target:
                    lp -= 1
                while rp < len(nums) - 1 and nums[rp + 1] == target:
                    rp += 1
                result[0] = lp
                result[1] = rp
                break
            elif nums[mp] < target:
                lp = mp + 1
            else:
                rp = mp - 1
        return result


if __name__ == "__main__":
    pass
